﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace WmsApp.UI
{
    public partial class QOutStoreBill : DevExpress.XtraEditors.XtraUserControl, IQueryControl
    {
        public QOutStoreBill()
        {
            InitializeComponent();
            if(GlobalClass.RunTimeMode)
            {
                DataBinding.Binding.BindingBillState(this.lookUpEditBillState);
                DataBinding.Binding.BindingGoodsCodeType(this.lookUpEditGoodsCodeType);
                DataBinding.Binding.BindOutStoreType(this.lookUpEditOutStoreType);
                DataBinding.Binding.BindStoreType(this.lookUpEditStoreType);
                DataBinding.Binding.BindUnit(this.lookUpEditUnit);
            }
        }

        public LookUpEdit LookUpEditOutStoreType
        {
            get { return this.lookUpEditOutStoreType; }
        }

        #region IQueryControl Members

        public string GetCondition()
        {
            string condition = "";
            if (lookUpEditBillState.EditValue != null && !String.IsNullOrEmpty(lookUpEditBillState.EditValue.ToString()))
            {
                condition += (String.Format(" and BillState ='{0}'", lookUpEditBillState.EditValue));
            }
            if (lookUpEditGoodsCodeType.EditValue != null && !String.IsNullOrEmpty(lookUpEditGoodsCodeType.EditValue.ToString()))
            {
                condition += (String.Format(" and BillID in ( select BillID from dbo.OutStoreBillDtl where  NewGoodsCode ='{0}' )", lookUpEditGoodsCodeType.EditValue));
            }
            if (lookUpEditOutStoreType.EditValue != null && !String.IsNullOrEmpty(lookUpEditOutStoreType.EditValue.ToString()))
            {
                condition += (String.Format(" and ExtVarChar1 ='{0}' ", lookUpEditOutStoreType.EditValue));
            }
            if (!String.IsNullOrEmpty(textEditProjectNo.Text) )
            {
                condition += (String.Format(" and ProjectNo like '%{0}%' ", textEditProjectNo.Text));
            }
            if (lookUpEditStoreType.EditValue != null && !String.IsNullOrEmpty(lookUpEditStoreType.EditValue.ToString()))
            {
                condition += (String.Format(" and BillID in ( select BillID from dbo.OutStoreBillDtl where  StoreTypeCode ='{0}' )", lookUpEditStoreType.EditValue));
            }
            if (lookUpEditUnit.EditValue != null && !String.IsNullOrEmpty(lookUpEditUnit.EditValue.ToString()))
            {
                condition += (String.Format(" and BillID in ( select BillID from dbo.OutStoreBillDtl where  UnitCode ='{0}' )", lookUpEditUnit.EditValue));
            }

            if (!String.IsNullOrEmpty(this.textEditOutStoreBIllID.Text))
            {
                condition += (String.Format(" and BillID  like '%{0}%'", textEditOutStoreBIllID.Text));
            }

            if (this.dateEditBillDateFrom.EditValue != null)
            {
                condition += (String.Format(" and BillDate  >= '{0}'", dateEditBillDateFrom.Text));
            }

            if (this.dateEditBillDateTo.EditValue != null)
            {
                condition += (String.Format(" and BillDate  <= '{0}'", dateEditBillDateTo.Text));
            }

            if (!String.IsNullOrEmpty(this.textEditPurpose.Text.Trim()))
            {
                condition += (String.Format(" and Purpose like '%{0}%'", this.textEditPurpose.Text.Trim()));
            }

            if (!String.IsNullOrEmpty(textEditNewGoodsName.Text.Trim()))
            {
                condition += (String.Format(" and BillID in ( select BillID from dbo.OutStoreBillDtl where  NewGoodsName  like '%{0}%' )", textEditNewGoodsName.Text.Trim()));
            }

            return condition;
        }

        #endregion

        #region IQueryControl Members


        public void AddCustomerCondition(string condition)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
